VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "CEventHandler"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'_______________________________________________________________________________________________________________
'***************************************************************************************************************
'   Class Module:   CEventHandler
'
'        This class module can trap events only for the workbook that contains it,
'        but no action is required to use it other than to create a new instance of
'        a public variable that references the class (see the Auto_Open procedure).
'
'_______________________________________________________________________________________________________________
'***************************************************************************************************************

Option Explicit



'=========================================================================
'   This variable traps all events generated by ThisWorkbook.
'=========================================================================
Private WithEvents wkbEventSource As Excel.Workbook




'____________________________________________________________________________________________________
'====================================================================================================
'   Sub: Class_Initialize
'
'       Class specific events. Instantiate the WithEvents variable when the class
'       is instantiated.
'
'====================================================================================================
Private Sub Class_Initialize()
    Set wkbEventSource = ThisWorkbook
End Sub





'____________________________________________________________________________________________________
'====================================================================================================
'   Sub: Class_Terminate
'
'       Destroy the WithEvents variable when the class is destroyed
'
'====================================================================================================
Private Sub Class_Terminate()
    Set wkbEventSource = Nothing
End Sub






' >>>>>
'_______________________________________ WORKBOOK  EVENTS __________________________________________
'%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%
' >>>>>





'____________________________________________________________________________________________________
'====================================================================================================
'   Sub: wkbEventSource_BeforeSave
'
'       Before saving
'
'====================================================================================================
Private Sub wkbEventSource_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    MsgBox "The Workbook_BeforeSave Event Fired.", vbInformation, wkbEventSource.Name
End Sub




'____________________________________________________________________________________________________
'====================================================================================================
'   Sub: wkbEventSource_NewSheet
'
'       Create a new sheet
'
'====================================================================================================
Private Sub wkbEventSource_NewSheet(ByVal Sh As Object)
    MsgBox "The " & TypeName(Sh) & " " & Sh.Name & " was added.", vbInformation, wkbEventSource.Name
End Sub




'____________________________________________________________________________________________________
'====================================================================================================
'   Sub: wkbEventSource_SheetBeforeRightClick
'
'       Before right click
'
'====================================================================================================
Private Sub wkbEventSource_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
    MsgBox "The Workbook_SheetBeforeRightClick Event Fired." & vbLf & "Sheet: " & Sh.Name & vbLf & "Range: " & Target.Address, vbInformation, wkbEventSource.Name
    Cancel = True
End Sub




'____________________________________________________________________________________________________
'====================================================================================================
'   Sub: wkbEventSource_SheetChange
'
'       On Sheet change
'
'====================================================================================================
Private Sub wkbEventSource_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    MsgBox "The Workbook_SheetChange Event Fired." & vbLf & "Sheet: " & Sh.Name & vbLf & "Range: " & Target.Address, vbInformation, wkbEventSource.Name
End Sub



















